package com.phiture.erp.produce.dal.mapper;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.phiture.erp.produce.dal.entity.ErpBomItemsDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * bom分录 Mapper
 *
 * @author lekaihuai
 */
@Mapper
public interface ErpBomItemsMapper extends BaseMapperX<ErpBomItemsDO> {

    default List<ErpBomItemsDO> selectListByFparentid(Long fparentid) {
        return selectList(ErpBomItemsDO::getFparentid, fparentid);
    }

    default int deleteByFparentid(Long fparentid) {
        return delete(ErpBomItemsDO::getFparentid, fparentid);
    }

    default Long selectMaxSeqByFparentid(Long fparentid){
        // 查询最大的序号, 如果查询结果不存在，返回 1
        ErpBomItemsDO result =  selectOne(new LambdaQueryWrapperX<ErpBomItemsDO>()
                .eq(ErpBomItemsDO::getFparentid, fparentid)
                .select(ErpBomItemsDO::getFseq)
                .orderByDesc(ErpBomItemsDO::getFseq)
                .last("limit 1"));
        return result != null ? result.getFseq() : 0L;
    }

}
